package datasource;
import datasource.config.C3P0Config;
import homework.jdbc.domain.User;
import java.sql.*;
import java.util.*;
public class UserDao {
    public int pageSize=3;
    List<User> list=new ArrayList<>();
    public List<User> findPage(int page) throws SQLException {
        Connection conn= C3P0Config.getConnection();
        String sql="select * from users order by id limit ?,?";
        PreparedStatement ps=conn.prepareStatement(sql);
        ps.setInt(1,pageSize*(page-1));
        ps.setInt(2,pageSize);
        ResultSet set = ps.executeQuery();
        while(set.next()){
            User user = new User(set.getInt(1),set.getString(2),set.getString(3));
            list.add(user);
        }
        return list;
    }
}
